package org.dut.transaction.controller;

import lombok.extern.slf4j.Slf4j;
import org.dut.transaction.service.LogService;
import org.dut.transaction.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private LogService logService;

    @Transactional(propagation = Propagation.NESTED)
    @RequestMapping("/insert")
    public Integer insertUser(String userName, String password) {
        userService.insertUser(userName, password);
        logService.insertLog(userName, "用户注册");
        log.info("insert user success");
        return 1;
    }

}

